import wx
# 背景色, 透明度
SELECT_BACKGROUND_COLOR = (150,202,204)
SELECT_OPACITY = 200

# 选择截图区域窗口
class SelectArea(wx.Frame):
    # 坐标原点在屏幕左上，x向右，y向下
    left,right,top,bottom = 0,0,0,0
    control = None

    def __init__(self, parent, control):
        wx.Frame.__init__(self, parent,
            style = wx.MAXIMIZE # 全屏显示
        )
        # 获取控制器实例
        self.control = control
        # 设置背景色
        self.SetBackgroundColour(SELECT_BACKGROUND_COLOR)
        # 设置透明度
        self.SetTransparent(SELECT_OPACITY)
        # 注册事件
        self.Bind(wx.EVT_LEFT_DOWN, self.OnDown, self)
        self.Bind(wx.EVT_LEFT_UP, self.OnUp, self)
        # 显示button
        self.Show(True)

    def OnDown(self, event):
        pos = event.GetPosition()
        self.top = pos.y
        self.left = pos.x
        
    def OnUp(self, event):
        pos = event.GetPosition()
        self.bottom = pos.y
        self.right = pos.x
        # 规格化四围坐标
        if self.top > self.bottom:
            self.top, self.bottom = self.bottom, self.top
        if self.left > self.right:
            self.left, self.right = self.right, self.left
        #print(self.left, self.top, self.right, self.bottom)
        #print(self.left, self.top, self.right-self.left, self.bottom-self.top)
        # 传递区域参数，创造区域
        self.control.changeArea((self.left, self.top), (self.right-self.left, self.bottom-self.top))
        self.Close()